package com.car.loan.project.cm.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.car.loan.common.enums.SwitchStatus;
import com.car.loan.common.enums.UserStatus;
import com.car.loan.project.cm.domain.CmBank;
import com.car.loan.project.cm.domain.CmBankScheme;
import com.car.loan.project.cm.mapper.CmBankSchemeMapper;
import com.car.loan.project.cm.service.ICmBankSchemeService;
import com.car.loan.project.cm.util.select.BankBaseDataSelect;
import com.car.loan.project.cm.util.select.BankSchemeBaseDataSelect;
import com.car.loan.project.cm.util.vo.SelectedVo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 银行按揭方案Service业务层处理
 *
 * @author ruoyi
 * @date 2019-10-19
 */
@Service
public class CmBankSchemeServiceImpl implements ICmBankSchemeService {

    @Autowired
    private CmBankSchemeMapper cmBankSchemeMapper;

    /**
     * 查询银行按揭方案
     *
     * @param id 银行按揭方案ID
     * @return 银行按揭方案
     */
    @Override
    public CmBankScheme selectCmBankSchemeById(Integer id) {
        return cmBankSchemeMapper.selectById(id);
    }

    /**
     * 查询银行按揭方案列表
     *
     * @param cmBankScheme 银行按揭方案
     * @return 银行按揭方案
     */
    @Override
    public List<CmBankScheme> selectCmBankSchemeList(CmBankScheme cmBankScheme) {
        QueryWrapper<CmBankScheme> queryWrapper = new QueryWrapper<>(cmBankScheme);
        return cmBankSchemeMapper.selectList(queryWrapper);
    }

    @Override
    public List<CmBankScheme> selectedList(BankSchemeBaseDataSelect bankSchemeBaseDataSelect) {
        CmBankScheme cmBankSchemeQuery = new CmBankScheme();
        cmBankSchemeQuery.setBankCarTypeId(bankSchemeBaseDataSelect.getBankCarTypeId());
        QueryWrapper<CmBankScheme> queryWrapper = new QueryWrapper<>(cmBankSchemeQuery);
        if (null == bankSchemeBaseDataSelect.getOf()
            || SwitchStatus.OPEN.status == bankSchemeBaseDataSelect
            .getOf()) {
            queryWrapper.eq("status", UserStatus.OK.getCode());
        } else {
            queryWrapper.in("status", UserStatus.OK.getCode(), UserStatus.DISABLE.getCode());
        }
        queryWrapper.orderByDesc("id");
        return cmBankSchemeMapper.selectList(queryWrapper);
    }

    /**
     * 新增银行按揭方案
     *
     * @param cmBankScheme 银行按揭方案
     * @return 结果
     */
    @Override
    public int insertCmBankScheme(CmBankScheme cmBankScheme) {
        return cmBankSchemeMapper.insert(cmBankScheme);
    }

    /**
     * 修改银行按揭方案
     *
     * @param cmBankScheme 银行按揭方案
     * @return 结果
     */
    @Override
    public int updateCmBankScheme(CmBankScheme cmBankScheme) {
        return cmBankSchemeMapper.updateById(cmBankScheme);
    }

    /**
     * 删除银行按揭方案对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCmBankSchemeByIds(Collection<Integer> ids) {
        return cmBankSchemeMapper.deleteBatchIds(ids);
    }

    /**
     * 删除银行按揭方案信息
     *
     * @param id 银行按揭方案ID
     * @return 结果
     */
    @Override
    public int deleteCmBankSchemeById(Integer id) {
        return cmBankSchemeMapper.deleteById(id);
    }
}
